﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Koonsoft.CustomerService.Entity;

namespace Koonsoft.CustomerService.DAL
{
    public static class ExtensionMethods
    {
        public static List<IssuesDifferent> GetDifferent(this Issue oldIssue, Issue newIssue)
        {
            Type type = oldIssue.GetType();

            List<IssuesDifferent> differents = new List<IssuesDifferent>();

            foreach (var v in type.GetProperties())
            {
                if(v.GetValue(oldIssue,null).ToString() != v.GetValue(newIssue,null).ToString())
                {
                    IssuesDifferent different= new IssuesDifferent();

                    different.FieldName = v.Name;
                    different.OldValue = v.GetValue(oldIssue,null).ToString();
                    different.NewValue = v.GetValue(newIssue,null).ToString();

                    differents.Add(different);
                }
            }
            return differents;
        }
    }

    public class IssuesDifferent
    {
        public string FieldName;
        public string OldValue;
        public string NewValue;
    }
}
